package cn.hdu.liang.ch5;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class Reducing {
    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(3,4,5,1,2);
        Integer sum = numbers.stream().reduce(0, Integer::sum);
        System.out.println(sum);

        sum = numbers.stream().reduce(1, (a, b) -> a * b);
        System.out.println(sum);

        Optional<Integer> max = numbers.stream().reduce(Integer::max);
        System.out.println(max.get());
    }
}
